from .models import Role
from utils.serializers import CustomModelSerializer
from rest_framework import serializers


class RoleSerializer(CustomModelSerializer):
    """
    角色管理-序列化器
    """
    used = serializers.SerializerMethodField()

    class Meta:
        model = Role
        fields = '__all__'
        read_only_fields = ['id']

    def get_used(self, obj):
        return obj.role.count()
